package cn.tedu._03vehicle.base.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import java.time.LocalDateTime;

@Slf4j
public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("preHandle拦截限定访问时间...");
        LocalDateTime now = LocalDateTime.now();
        int hour = now.getHour();
        if (hour < 6 || hour > 22){
            throw new RuntimeException("当前时间段不允许访问！请在6:00到23:00之间访问");

        }
        return true;
    }
}
